﻿using CSCSN.EntitiyModels;
using CSCSN.EntitiyModels.ApplicationTaskAbout;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System;

namespace CSCSN.ORM
{
    public class CsDbContext: IdentityDbContext<IdentityUser<Guid>, IdentityRole<Guid>, Guid>
    {
        public CsDbContext(DbContextOptions<CsDbContext> options) : base(options)
        {

        }
        public DbSet<ApplicationTaskType> ApplicationTaskTypes { get; set; }
        public DbSet<ApplicationRole> ApplicationRoles{ get; set; }
        public DbSet<ApplicationUserData> ApplicationUserDatas { get; set; }
        public DbSet<ApplicationUser> ApplicationUsers { get; set; }
        public DbSet<ApplicationTask> ApplicationTasks { get; set; }
        public DbSet<ApplicationUserWithApplicationTask> ApplicationUserWithApplicationTasks { get; set; }
        public DbSet<TaskSite> TaskSites { get; set; }



        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
            builder.Entity<ApplicationTask>()
                .HasOne(s => s.ApplicationTaskTypes)
                .WithMany()
                .HasForeignKey(p => p.ApplicationTaskTypesID)
                .OnDelete(DeleteBehavior.SetNull);           //设置任务表与任务类型表的级联删除关系
        }
    }
}
